﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyFound.UI
{
    public partial class AddFoundForm : Form
    {
        public AddFoundForm()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            var code = (textBox1.Text ?? "").Trim();
            if (string.IsNullOrWhiteSpace(code) == false && Regex.IsMatch(code, @"\d{6}"))
            {
                var foundList = FoundApi.ListFound(new[] { code });
                if (foundList.ContainsKey(code))
                {
                    var found = foundList[code];
                    ShowFound(found);
                }
            }
        }

        private void ShowFound(Class1 found)
        {
            this.textBox2.Text = found.Name;
        }

        private void AddFound_Load(object sender, EventArgs e)
        {

        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            var code = (textBox1.Text ?? "").Trim();
            if (string.IsNullOrWhiteSpace(code) == false && Regex.IsMatch(code, @"\d{6}"))
            {
                MyFound.Program.AddFound(code);
            }
            MessageBox.Show(@"添加成功", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.textBox1.Clear();
            this.textBox2.Clear();
        }
    }
}
